package com.mobile.challenge.web;

import com.mobile.challenge.core.Result;
import com.mobile.challenge.core.ResultGenerator;
import com.mobile.challenge.model.RuleTitle;
import com.mobile.challenge.service.RuleTitleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by Lix on 2018/06/04.
*/
@RestController
@RequestMapping("/rule")
@Api(value = "活动规则接口",tags = {"挑战规则"})
public class RuleController {
    @Resource
    private RuleTitleService ruleTitleService;

    /**
     * 活动过期情况
     * @return
     */
    @RequestMapping(value = "/selOverdue", method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取活动过期情况")
    public Result selOverdue(){
        Map data = new HashMap();
        Map rs = ruleTitleService.isOverdue();
        if(!(boolean)rs.get("code")){
            return ResultGenerator.genFailResult((String) rs.get("msg"),data);
        }
        return ResultGenerator.genSuccessResult(data);
    }

    /**
     * 获取活动规则
     * @return
     */
    @RequestMapping(value = "/details", method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取活动规则")
    public Result getRule() {
        List<RuleTitle> ruleTitles = ruleTitleService.selRule();
        Map data = new HashMap();
        data.put("ruleList",ruleTitles);

        return ResultGenerator.genSuccessResult(data);
    }
}
